//
// Created by korack on 25-5-17.
//
#pragma once

#include <giomm/socketclient.h>
#include <giomm/socketconnection.h>
#include <giomm/iostream.h>

namespace Mp {

class Network final : public Glib::Object
{
  Glib::RefPtr<Gio::SocketClient> m_socketClient;

  Glib::RefPtr<Gio::SocketConnection> conn;
  Glib::RefPtr<Gio::OutputStream> out_stream;
  Glib::RefPtr<Gio::InputStream> in_stream;
  bool is_connected;

public:
  Network();
  ~Network() override;

  static Glib::RefPtr<Network> create();

  void connect_to_server(const std::string &server_address, int port);
  void register_to_server() const;

  void send_messages(const std::string &msg_type,
		     const std::string &message) const;

  void close_connection() const;
};

} // namespace Mp
